<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.model.Building"%>
<%@ page import="com.model.Rate"%>
<%@ page import="com.control.BuildingControl"%>
<%@ page import="com.control.AdminControl"%>
<%@ page import="com.control.RateControl"%>
<%@ page import="com.util.PageResultSet"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>显示卫生评分结果</title>
	</head>
	<body>
		<%
	    request.setCharacterEncoding("UTF-8");
	    String ToolBar = "";
	    int curPage = 1;
	    int admin_id = (Integer)session.getAttribute("user_id");
		AdminControl acontrol = new AdminControl();
		int admin_building = acontrol.getAdmin(admin_id).getAdmin_building_id();
		int rate_building = admin_building;
	    Calendar date = Calendar.getInstance();
		int month = date.get(Calendar.MONTH) + 1;
		int year = date.get(Calendar.YEAR);
	   	if(request.getParameter("rate_building") != null ) {
	    	rate_building = Integer.parseInt(request.getParameter("rate_building"));
	    	session.setAttribute("rate_building",rate_building);
	    	year = Integer.parseInt(request.getParameter("year"));
	    	session.setAttribute("year",year);
	    	month = Integer.parseInt(request.getParameter("month"));
	    	session.setAttribute("month",month);
	    }
	%>
		<table width="98%" border="0" align="center">
			<tr>
				<td></td>
			</tr>
			<tr>
				<td></td>
			</tr>
			<tr>
				<td>
					<fieldset>
						<legend>
							查看寝室卫生情况
						</legend>
						<form action="Give_score_show.jsp" name="form1" method="post">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr height="10">
									<td></td>
								</tr>
								<tr align="center">
									<td align="center">
										请选择寝室楼:
										<select name="rate_building" size="1">
											<option value="0" <%if(rate_building == 0) {%>selected="selected"<%}%>>全部</option>
											<%
											 if(session.getAttribute("rate_building") != null) {
	    										rate_building = (Integer)session.getAttribute("rate_building");
	    									}
											BuildingControl control = new BuildingControl();
											ArrayList<Building> blist = new ArrayList<Building>();
											blist = control.getBuildingList(); 
											for(int i=0; i<blist.size(); i++) {
												Building building = blist.get(i);
										%>
											<option value="<%= building.getBuilding_id()%>" <%if(rate_building == building.getBuilding_id()%><%){%>selected="selected"<%}%>><%=building.getBuilding_name() %></option>
											<%}%>
											
										</select>
										&nbsp;&nbsp;日期:<select name="year" size="1">
										<%
											if(session.getAttribute("year")!=null) {
												year = (Integer)session.getAttribute("year");
												month = (Integer)session.getAttribute("month");
											}
											for(int y=2010; y<=2018; y++) {
										%>
										<option value="<%=y %>" <%if(year == y) {%>selected="selected"<%}%>><%=y %></option>
										<%} %>
										</select>年
										<select name="month" size="1">
										<%
											for(int m=1; m<=12; m++) {
										%>
										<option value="<%=m %>" <%if(month == m) {%>selected="selected"<%}%>><%=m %></option>
										<%} %>
										</select>月
										<input type="submit" value="查询" />
									</td>
								</tr>
							</table>
							<table width="70%" border="0" align="center" cellspacing="0"
								cellpadding="0">
								<tr>
									<td height="20"></td>
								</tr>
								<tr>
									<td>
										<table border="1" width="99%" align="center" cellpadding="0"
											cellspacing="1" class="resultTable">
											<tr>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													寝室楼
												</td>
												<td width="3%" height="25" align="center" bgcolor="#D9F0FF">
													寝室
												</td>
												<td width="3%" height="25" align="center" bgcolor="#D9F0FF">
													寝室长
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													卫生等级
												</td>
												<td width="6%" height="25" align="center" bgcolor="#D9F0FF">
													评语
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													评分人
												</td>
												<td width="6%" height="25" align="center" bgcolor="#D9F0FF">
													评价时间
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													修改
												</td>
								</tr>
								<%
									RateControl rcontrol = new RateControl();
									ArrayList<Rate> list = new ArrayList<Rate>();
									String start_time = "";
									String end_time = "";
									start_time += year + "-" + month + "-1" ;
									if(month<12)
										end_time += year + "-" + (month+1) + "-1";
									else
										end_time += (year+1) + "-" + 1 + "-1";
									list = rcontrol.getRateInformation(rate_building,start_time,end_time);
									if(request.getParameter("cur_page")!= null) {
										curPage = Integer.parseInt(request.getParameter("cur_page")); 
									}
									PageResultSet p = new PageResultSet(list,curPage);
									ArrayList<Rate> nowlist = new ArrayList<Rate>();
									nowlist = (ArrayList<Rate>)p.getData();
									//out.println(list.size());
									for(int i=0; i<nowlist.size(); i++) {
										Rate rate = nowlist.get(i);
								 %>
								 	<tr>
        								<td height="25" align="center"><%=rate.getBuilding_name()%></td>
 										<td height="25" align="center"><%=rate.getDorm_name()%></td>
 										<td height="25" align="center"><%=rate.getDorm_leader()%></td>
 										<td height="25" align="center"><%=rate.getRate_score()%></td>
 										<td height="25" align="center"><%=rate.getRate_des()%></td>
 										<td height="25" align="center"><%=rate.getAdmin_name()%></td>	
 										<td height="25" align="center"><%=rate.getRate_time()%></td>	
 										<%
 										if(rate_building == admin_building){
 										%>
 		 								<td height="25" align="center"><a href="update_score.jsp?id=<%=rate.getRate_id()%>&dorm_name=<%=rate.getDorm_name() %>">修改</a></td>
 		 								<%} 
 		 								else {%>
 		 								<td height="25" align="center">无权修改</td>
 		 								<%} %>	
   									</tr>
   									<%}
   										String fileName = "Give_score_show.jsp";
										ToolBar = p.getToolBar(fileName);
   									%>
							</table>
							<%=ToolBar %>
							</td>
							</tr>
							</table>
						</form>
					</fieldset>
				</td>
			</tr>
		</table>
	</body>
</html>
